<!--suppress ALL -->
<template>
    <div class="page home-page" data-page="home">
        <div class="link-tab-page-top">
            <div class="link-tab-page-title" id="userNameHome"></div>
            <a href="#" class="link bind-homeScanning">
                <i class="link-icon link-icon-scan"></i>
            </a>
        </div>
        <div class="page-content home-content ptr-content" @ptr:refresh="refreshCards" id="page-content-scroll">
            <div class="ptr-preloader home-top-refresh">
                <div class="preloader color-multi"></div>
                <div class="ptr-arrow"></div>
            </div>
            <!-- 首页卡片 -->
            <div class="cards-content unit-cards-content"></div>
        </div>
    </div>
</template>

<script>
    return {
        mounted() {
            var self = this;
            self.getCards();
        },
        data: function () {
            return {
                pageName: "home",
                cardsList: [],  //定义接收的字段
            }
        },
        methods: {
            //获取卡片数据
            getCards: function(){
                common.loading(1);
                var self = this;
                var $ = self.$$;
                var orgId="";
                if(single_Orgid.toString().indexOf(",")==-1){
                    orgId=single_Orgid;
                }else{
                    orgId="";
                }
                Dao.unitStateList({
                    userName: userInfor.accountName,
                    deviceId: appKeyObj.deviceId,
                    userAccount: userInfor.accountName,
                    isMuilUnitUser: userInfor.isMuilUnitUser,
                    status: 1,
                    orgCode: platformCode || app.data.defaultPlatCode,
                    orgId:orgId
                }, function (data) {
                    self.cardsList = data;
                    globalCardList = data;
                    self.setCardDom(data);
                });
            },
            //设置卡片Dom
            setCardDom: function () {
                var self = this;
                var $ = self.$$;
                jQuery(".cards-content").empty();
                if (self.cardsList && self.cardsList.length > 0) {
                    for (var i = 0; i < self.cardsList.length; i++) {
                        $(".cards-content").append('<div class="view  card-view-style card-view-' + self.cardsList[i].id + '" id="' + self.cardsList[i].link + '" data-name="' + self.cardsList[i].link + '"></div>');
                    }
                    self.showEveryCards();
                }else{
                    $(".cards-content").append(`<div class="no-data-img" style="margin-top: 50%;"><img src='`+listNoDataPic()+`'/></div>`);
                }
                common.loading(0);
            },
            //卡片嵌入页面
            showEveryCards: function () {
                var self = this;
                var $ = self.$$;
                if (self.cardsList && self.cardsList.length > 0) {
                    for (var i = 0; i < self.cardsList.length; i++) {
                        app.views.create('#' + self.cardsList[i].link, {url: '/' + self.cardsList[i].link + '/'});
                    }
                }
            },
            //刷新
            refreshCards: function (e, done) {
                var self = this;
                var $ = self.$$;
                $(".home-top-refresh").show();
                if (done && e) {
                    setTimeout(function () {
                        self.getCards();
                        done();
                        $(".home-top-refresh").hide();
                    },1000);
                }
            },
        },
        on: {
            pageInit: function (e, page) {
                var self = this;
                //如果是九小用户
                if(userInfor.role[0].id == 143){
                    jQuery("#userNameHome").html(nineCodeName);
                }else{
                    jQuery("#userNameHome").html(single_OrgName);
                }
                //原生扫一扫
                jQuery(".bind-homeScanning").off().click(function () {
                    native.scanQrCode();
                });

                window.getCards_home = self.refreshCards;

                //最后一个page进入的时候
                if(self.cardsList.length > 0){
                    if(self.cardsList[self.cardsList.length-1].link == page.route.name){
                        setTimeout(function(){
                            common.loading(0);
                        },500);
                    }
                }

                if(app.data.isFirstLoad){
                    app.data.isFirstLoad=false;
                    getPublicReouse();
                }
            },

        }
    }
</script>